﻿using OrchardCore.DisplayManagement.Handlers;

using OrchardCore.DisplayManagement.Views;

using Ruitu.Edu.TrainingDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ruitu.Edu.TrainingDemo.Drivers
{
    public sealed class BookDisplayDriver : DisplayDriver<Book>
    {
        public override IDisplayResult Display(Book model, BuildDisplayContext context)
        {
            var results = new List<IDisplayResult>
            {
                View($"{nameof(Book)}_Display_Title", model)
                    .Location("Header: 1"),
                View($"{nameof(Book)}_Display_Author", model)
                    .Location("Header: 2"),
                View($"{nameof(Book)}_Display_Cover", model)
                    .Location("Cover: 1"),
                View($"{nameof(Book)}_Display_Description", model)
                    .Location("Detail0", "Content: 1")
            };

            // 如果是Detail区域，添加Description显示
            //if (context.DisplayType == "Detail")
            //{
            //    results.Add(
            //        View($"{nameof(Book)}_Display_Description", model)
            //            .Location("Detail", "Detail: 1")
            //    );
            //}

            return Combine(results.ToArray());
        }
    }
}
